<template>
    <div>
        <el-row>
            <el-col :span="18">
                <el-input v-model="input" disabled/>
            </el-col>
            <el-button @click="popupSelectDidlog">...</el-button>
        </el-row>
        <el-dialog title="值列表" :visible.sync="displaySelectDialog" width="40%" center="">
            <el-row>
                <el-col :span="12">
                    <el-select v-model="selectValue" multiple placeholder="请选择">
                     <el-option
                            v-for="item in parentCodeArray"
                            :label="item"
                            :value="item">
                    </el-option>
                    </el-select>
                </el-col>
                <el-col :span="10" align="center">
                    <el-button @click="cancle">取 消</el-button>
                    <el-button type="primary" @click="sureSelect">确 定</el-button>
                </el-col>
            </el-row>

        </el-dialog>

    </div>

</template>

<script>
    /*子组件引入父组件的api*/
    import {getTreeSetDetailByTreeId_Url,} from "@/config/api";

    export default {
        name: "selectComponent",

        /*接收父组件传递给子组件的值*/
        props:{
            fatherModuleTransmitData:{
                type:String,
            }
        },

        data() {
            return {

                /*下拉框选中后的值*/
                selectValue: [],

                /*选择弹框标识*/
                displaySelectDialog:false,

                /*父级编码数组*/
                parentCodeArray:[],

                input:''
            };
        },
        created() {
            //alert("父组件传递给子组件的值为：===>>>"+this.fatherModuleTransmitData);
        },
        methods:{

            popupSelectDidlog(){
                //alert("查询传递的值是否已改变：===>>>"+this.fatherModuleTransmitData);
                /*调用父组件接口查询已存在的从表上级编码*/
                if(this.fatherModuleTransmitData!=""||null!=this.fatherModuleTransmitData){
                    this.autoLoadMinorTableData();
                }
                this.displaySelectDialog = true;
            },

            /*加载从表数据事件*/
            autoLoadMinorTableData(){
                getTreeSetDetailByTreeId_Url({
                    treesetId:this.fatherModuleTransmitData
                }).then( resp =>{
                    //console.log("从表的数据为：===>>>"+JSON.stringify(resp));
                    if(resp.data.success){
                        if(resp.data.data.length>0){
                            for(var index = 0;index<resp.data.data.length;index++){
                                if(resp.data.data[index].treedetailNo!=""||resp.data.data[index].treedetailNo!=null){
                                    this.parentCodeArray.push(resp.data.data[index].treedetailNo);
                                }
                            }
                        }else{
                            this.parentCodeArray = [];
                        }
                    }else{
                        this.parentCodeArray = [];
                    }
                })
            },

            /*下拉框选择确定事件*/
            sureSelect(){
                if(this.selectValue.length>0){
                    if(this.selectValue.length>=2){
                        this.$message(' 只能选择一个数据！！！');
                    }else{
                        for(var index=0;index<this.selectValue.length;index++){
                            this.input = this.selectValue[index];
                        }
                        /*子组件被动向父组件传递参数*/
                        this.$emit("listenSingleSelect", this.input);
                        this.parentCodeArray = [];
                        this.displaySelectDialog = false;
                    }

                }else{
                    this.input ="";
                    /*子组件被动向父组件传递参数*/
                    this.$emit("listenSingleSelect", this.input);
                    this.displaySelectDialog = false;
                    this.parentCodeArray = [];

                }


            },

            /*弹框取消*/
            cancle(){
                this.displaySelectDialog = false;
                this.parentCodeArray = [];
            }
        }
    }
</script>

<style scoped>

</style>